package com.monkey.core.domain.auth;

import com.monkey.core.domain.role.Role;
import com.monkey.core.domain.user.User;
import com.monkey.core.repository.BaseRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

/**
 * Created by silentwu on 2015/8/4.
 */
public interface UserRoleRepository extends BaseRepository<UserRole, Long> {

    @Modifying
    @Query("delete from UserRole u where u.user.id = ?1 and u.role.id = ?2")
    void deleteByUserIdAndRoleId(Long userId, Long roleId);

    @Query("from UserRole u where u.user.id = ?1")
    List<UserRole> findByUserId(Long userId);

    List<Role> findByUser(User user);
}
